/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.scuecsz.view.mbean.common;

import java.awt.Graphics2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.scuecsz.view.utils.VerifyCode;

/**
 *
 * @author Administrator
 */
public class DefaultMbean implements Serializable {

    protected List queryValues;
    //用于生产验证码
    protected String vCode;
    protected VerifyCode vc;
    //分页属性
    protected List pageNums;
    protected int pageNum = 1;
    protected int size =5;
    protected int maxPage;

    public void newVCodeActon() {
        vc.getNewCodes(4);
    }

    public VerifyCode getVc() {
        if (null == vc) {
            vc = new VerifyCode();
            vc.getNewCodes(4);
        }
        return vc;
    }

    public void setVc(VerifyCode vc) {
        this.vc = vc;
    }

    public String getvCode() {
        return vCode;
    }

    public void setvCode(String vCode) {
        this.vCode = vCode;
    }

    public String paintVerifyCode(Graphics2D g2d, Object obj) {
        VerifyCode data = (VerifyCode) obj;
        data.paintVerifyCode(g2d);
        g2d.dispose();
        return null;
    }

    protected String nextPage() {
//        System.out.println("now"+pageNum+"/"+maxPage);
        if (pageNum < maxPage) {
            pageNum++;
        }
//        System.out.println("next"+pageNum+"/"+maxPage);
        return null;
    }

    protected String prePage() {
//        System.out.println(pageNum+"/"+maxPage);
        if (pageNum > 1) {
            pageNum--;
        }
//        System.out.println("pre"+pageNum+"/"+maxPage);
        return null;
    }

    public List getPageNums() {
        if (null == pageNums) {
            pageNums = new ArrayList();
            pageNums.add(new SelectItem(String.valueOf(1)));
            for (int i = 2; i <= maxPage; i++) {
                pageNums.add(new SelectItem(String.valueOf(i)));
            }
        } else {
            SelectItem item = (SelectItem) pageNums.get(pageNums.size() - 1);
            int maxPageNum = Integer.parseInt(String.valueOf(item.getValue()));
            if (maxPageNum > maxPage) {
                for (int i = maxPage + 1; i <= maxPageNum - maxPage; i++) {
                    pageNums.add(new SelectItem(String.valueOf(i)));
                }
            } else if (maxPageNum < maxPage) {
                 for (int i = maxPage; i <= maxPage - maxPageNum; i++) {
                    pageNums.remove(i);
                }
            }
        }
        return pageNums;
    }

    public void setPageNums(List pageNums) {
        this.pageNums = pageNums;
    }

    public int getMaxPage() {
        return maxPage;
    }

    public void setMaxPage(int maxPage) {
        this.maxPage = maxPage;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }
}
